capture log close
log using dadvars.txt, text replace

use NATL2005US.AllCnty.basicdemography.dta, clear
foreach y in 2006 2007 2008 2009 2010 2011 2012 2013 {
append using NATL`y'US.AllCnty.basicdemography.dta, nolabel
}
tab dob_yy, mi
desc, fullnames

label variable fagerpt_flg "Father's reported age used"
label define fagerpt_flg 1 "Father's reported age used"
label values fagerpt_flg fagerpt_flg

label variable fagecomb "Father's combined age (revised)"
label define fagecomb 99 unknown
label values fagecomb fagecomb

label variable fagerec11 "Father's age recode 11"
label define fagerec11 1 "under 15" 2 "15-19" 3 "20-24" 4 "25-29" 5 "30-34" 6 "35-39" 7 "40-44" 8 "45-49" 9 "50-54" 10 "55-98" 11 unknown
label values fagerec11 fagerec11

label variable fbrace "Father's bridged race"
label define fbrace 1 white 2 black 3 "american indian" 4 "asian indian" 5 chinese 6 filipino 7 japanese 8 korean 9 vietnamese 10 "other asian" 11 hawaiian 12 guamanian 13 samoan 14 "other pacific islander" 15 other 21 "bridged white" 22 "bridged black" 23 "bridged american indian & alaskan native" 24 "bridged asian/pacific islander" 99 unknown
label values fbrace fbrace

label variable ufhisp "Father's hispanic origin-unrevised"
label define ufhisp 0 "non-hispanic" 1 mexican 2 "puerto rican" 3 cuban 4 "central or south american" 5 "other and unknown hispanic" 9 unknown
label values ufhisp ufhisp

label variable ufrace "Father's race (unrevised)"
label define ufrace 1 white 2 black 3 "american indian & alaskan native" 4 chinese 5 japanese 6 hawaiian 7 filipino 18" asian indian" 28 korean 38 samoan 48 vietnamese 58 guamanian 68 "other asian or pac islndr" 78 "combined other asian or pac islndr" 99 unknown
label values ufrace ufrace

foreach v of varlist  dobf_mm dobf_dd dobf_imp dobf_yy dobf_byp fagerpt_flg fagerpt fagecomp ufagecomp fagecomb ufagecomb fagerec11 fbrace fraceimp fracerec fhisp ufhisp fracehisp feducA  feduc_byp  ufrace  fmultirace {
display ""
display "`v'"
tab `v', mi
}

misstable summarize  dobf_mm dobf_dd dobf_imp dobf_yy dobf_byp fagerpt_flg fagerpt fagecomp ufagecomp fagecomb ufagecomb fagerec11 fbrace fraceimp fracerec fhisp ufhisp fracehisp feducA  feduc_byp  ufrace  fmultirace 

count if missing(fagerec11)
count if missing(fracerec)
count if missing(ufhisp)
count if missing(fracehisp)

tab ufagecomb, mi
tab fracerec, mi
tab fracehisp, mi
tab feducA, mi

gen fage_missing = 0
replace fage_missing = 1 if ufagecomb == .
gen fracerec_missing = 0
replace fracerec_missing = 1 if fracerec == .
gen fracehisp_missing = 0
replace fracehisp_missing = 1  if fracehisp == .
gen feducA_missing = 0
replace feducA_missing = 1 if feducA == .

gen fage_unknown = 0
replace fage_unknown = 1 if ufagecomb == 99  
gen fracerec_unknown = 0
replace fracerec_unknown = 1 if fracerec == 9 
gen fracehisp_unknown = 0
replace fracehisp_unknown = 1  if fracehisp == 9 
gen feducA_unknown = 0
replace feducA_unknown = 1 if feducA == 9

gen fage_missing_unknown = 0
replace fage_missing_unknown = 1  if fage_missing == 1 | fage_unknown == 1
gen fracerec_missing_unknown = 0
replace fracerec_missing_unknown = 1  if fracerec_missing == 1 | fracerec_unknown == 1
gen fracehisp_missing_unknown = 0
replace fracehisp_missing_unknown = 1  if fracehisp_missing == 1 | fracehisp_unknown == 1
gen feducA_missing_unknown = 0
replace feducA_missing_unknown = 1  if feducA_missing == 1 | feducA_unknown == 1

tab fage_missing dob_yy, mi col
tab fracerec_missing dob_yy, mi col
tab fracehisp_missing dob_yy, mi col
tab feducA_missing dob_yy, mi col

tab fage_unknown dob_yy, mi col
tab fracerec_missing dob_yy, mi col
tab fracehisp_missing dob_yy, mi col
tab feducA_missing dob_yy, mi col


tab fage_missing_unknown dob_yy, mi col
tab fage_missing_unknown dob_yy if dob_yy < 2012, mi col
tab fracerec_missing_unknown dob_yy, mi col
tab fracehisp_missing_unknown dob_yy, mi col
tab feducA_missing_unknown dob_yy, mi col
tab feducA_missing_unknown dob_yy if dob_yy > 2008, mi col

gen missing_all_dad_info = 0
replace missing_all_dad_info = 1 if dob_yy >= 2009 & dob_yy <= 2011 & fage_missing_unknown == 1 & fracerec_missing_unknown == 1 & fracehisp_missing_unknown == 1 & feducA_missing_unknown == 1
replace missing_all_dad_info = 1 if dob_yy <= 2008 & fage_missing_unknown == 1 & fracerec_missing_unknown == 1 & fracehisp_missing_unknown == 1 
replace missing_all_dad_info = 1 if dob_yy >= 2012 & fracerec_missing_unknown == 1 & fracehisp_missing_unknown == 1 & feducA_missing_unknown == 1
tab missing_all_dad_info dob_yy, mi col














